package com.tech.connect.huanzhewan;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanWanPinGuiActivity extends BaseActivity {


    private List<String> allHaveList = new ArrayList<>();
    private List<String> allNoList = new ArrayList<>();
    private BaseAdapter<String, BaseHolder> haveAdapter;
    private BaseAdapter<String, BaseHolder> noAdapter;
    private RecyclerView haveRecycler;
    private RecyclerView noRecycler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_huanzhewan_wanpingui);
        getHeadBar().setTitle("玩品柜");
        initView();
        initHaveAdapter();
        initNoAdapter();
    }


    private void initView() {
        haveRecycler = findViewById(R.id.haveRecycler);
        noRecycler = findViewById(R.id.noRecycler);
        haveRecycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
        noRecycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
        haveRecycler.addItemDecoration(new HLineDivider());
        noRecycler.addItemDecoration(new HLineDivider());
    }

    private void initHaveAdapter() {
        if (haveAdapter == null) {
            haveAdapter = new BaseAdapter<String, BaseHolder>(R.layout.item_huanzhewan_wanpingui, allHaveList, 4) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    CheckBox checkBoxLeft = helper.getView(R.id.checkboxLeft);
                    CheckBox checkboxRight = helper.getView(R.id.checkboxRight);
                    checkboxRight.setVisibility(View.GONE);
                }
            };
            haveRecycler.setAdapter(haveAdapter);
        }
        haveAdapter.notifyDataSetChanged();
    } private void initNoAdapter() {
        if (noAdapter == null) {
            noAdapter = new BaseAdapter<String, BaseHolder>(R.layout.item_huanzhewan_wanpingui, allNoList, 2) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    CheckBox checkBoxLeft = helper.getView(R.id.checkboxLeft);
                    CheckBox checkboxRight = helper.getView(R.id.checkboxRight);
                    checkboxRight.setVisibility(View.GONE);
                }
            };
            noRecycler.setAdapter(noAdapter);
        }
        noAdapter.notifyDataSetChanged();
    }

}
